
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <memory.h>
#include "../container/compress_algo.h"

using namespace std;

int main() {
	const int n = 10003457;
	cout << "n = " << n << endl;
	char* data = new char[n];
	memset(data, 0, sizeof(char)*n);
	for(int i = 0; i < n; i++) {
		if(rand()%2) {
			data[i] = 1;
		}
	}
	const int nWord = ceil(n/(sizeof(int)*8.0f));
	unsigned int* word = new unsigned int[nWord];

	//encoding
	unsigned int numWord = 0;
	bitEncode(word, &numWord, data, n);
	assert(nWord == numWord);
	cout << "encoding done, numWord = " << numWord << endl;

	//decoding
	char* result = new char[n];
	bitDecode(result, n, word, numWord);

	//check result
	for(int i = 0; i < n; i++) {
		if(result[i] != data[i]) {
			cout << "!!!ERROR" << endl;
			exit(-1);
		}
	}
	cout << "Test pass :)" << endl;

	return EXIT_SUCCESS;
}

